﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;

namespace HZ.Supervise.Model
{
    public class TableInfo
    {
        public string Name { get; set; }
        public string Fields { get; set; }
        public string Table { get; set; }
        public string Alias { get; set; }

        private static IDictionary<string, TableInfo> _GroupFieldTableInfo = null;
        public static IDictionary<string, TableInfo> GroupFieldTableInfo
        {
            get
            {
                if (_GroupFieldTableInfo == null)
                {
                    _GroupFieldTableInfo = new Dictionary<string, TableInfo>();

                    Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("HZ.Supervise.Model.TableInfo.xml");
                    XmlReaderSettings settings = new XmlReaderSettings() { IgnoreWhitespace = true, CloseInput = true };
                    XmlReader reader = XmlReader.Create(stream, settings);

                    while (reader.Read())
                    {
                        if (reader.HasAttributes && reader.Name == "add")
                        {
                            TableInfo info = new TableInfo()
                            {
                                Name = reader["Name"],
                                Fields = reader["Fields"],
                                Table = reader["Table"],
                                Alias = string.IsNullOrEmpty(reader["Alias"]) ? reader["Table"] : reader["Alias"] //若别名为空则使用表名
                            };

                            _GroupFieldTableInfo.Add(reader["Name"], info);
                        }
                    }
                    reader.Close();


                }

                return _GroupFieldTableInfo;


            }
        }
    }
}
